home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / ed / eecad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-18  |  67.1 KB  |  1,894 lines

  1. /*****************************************************************************
  2. *   Program to draw EE diagrams.                         *
  3. *                                         *
  4. * Usage:                                     *
  5. *                                         *
  6. * Written by:  Gershon Elber            IBM PC Ver 2.0, Aug. 1990    *
  7. *****************************************************************************/
  8.  
  9. #include <math.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <conio.h>
  13. #include <string.h>
  14. #include <time.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <alloc.h>
  18. #include <time.h>
  19. #include "Program.h"
  20. #include "EELibs.h"
  21. #include "EECreate.h"
  22. #include "EERedraw.h"
  23. #include "EEStatus.h"
  24. #include "EEString.h"
  25. #include "EEModify.h"
  26. #include "EELoad.h"
  27. #include "EELayer.h"
  28. #include "Director.h"
  29. #include "Ctrl-Brk.h"
  30. #include "Config.h"
  31.  
  32. #define WINDOWS_FRAME_WIDTH 8
  33. #define MAX_NUM_OF_OPEN_WINDOWS 50
  34.  
  35. #define DEFAULT_LIB_DIR "."        /* Current directory is the default. */
  36.  
  37. /* Undef DEBUG_MALLOC_TC20 iff you have TurboC 2.0. It assumes the offset    */
  38. /* part of the pointer is always 8 which is TRUE only of TC 2.0.         */
  39. /* #define DEBUG_MALLOC_TC20  /* Add debugging aid for malloc/free routines. */
  40.  
  41. /* Undef DEBUG_MALLOC_TCPP iff you have TurboC++ 1.0. It uses heap testing   */
  42. /* routines introduced in this version.                         */
  43. /* #define DEBUG_MALLOC_TCPP  /* Add debugging aid for malloc/free routines. */
  44.  
  45. #define DIRECT_CALL_INDEX_OFFSET    100
  46. #define MAX_KEY_BINDINGS    100
  47.  
  48. typedef struct {
  49.     int ScanCode;        /* Scan code to activate the following function. */
  50.     int Menu;                        /* Pull Down Menu index. */
  51.     int MenuEntry;                  /* Pull Down Menu entry index. */
  52. } KeyBindingStruct;
  53.  
  54. int EESnapDistance = DEFAULT_SNAP_DISTANCE,
  55.     EETextScale = 1,
  56.     EEWindowsFrameWidth = 8,               /* Width of all drawings. */
  57.     EEListNumDisplayed = 30,
  58.     EERootWindowID = -1,
  59.     EERootWndwFrameColor = INTR_COLOR_MAGENTA,
  60.     EERootWndwForeColor = INTR_COLOR_YELLOW,
  61.     EERootWndwBackColor = INTR_COLOR_BLUE,
  62.     EERootWndwXorColor = INTR_COLOR_CYAN,
  63.     EEPopUpFrameColor = INTR_COLOR_RED,   /* Color for pop up menus/queries. */
  64.     EEPopUpBackColor = INTR_COLOR_MAGENTA,
  65.     EEPopUpForeColor = INTR_COLOR_YELLOW,
  66.     EEPopUpXorColor = INTR_COLOR_YELLOW,
  67.     EEActvWndwFrameColor = INTR_COLOR_RED,
  68.     EEActvWndwForeColor = INTR_COLOR_YELLOW,
  69.     EEActvWndwBackColor = INTR_COLOR_BLUE,
  70.     EEPsvWndwFrameColor = INTR_COLOR_RED,
  71.     EEPsvWndwForeColor = INTR_COLOR_YELLOW,
  72.     EEPsvWndwBackColor = INTR_COLOR_BLUE,
  73.     EEHighLightColor = INTR_COLOR_RED,
  74.     EELayerWire = INTR_COLOR_WHITE,
  75.     EELayerBus = INTR_COLOR_WHITE,
  76.     EELayerGate = INTR_COLOR_WHITE,
  77.     EELayerIEEE = INTR_COLOR_WHITE,
  78.     EELayerPinFun = INTR_COLOR_WHITE,
  79.     EELayerPinNum = INTR_COLOR_WHITE,
  80.     EELayerPinNam = INTR_COLOR_WHITE,
  81.     EELayerRefDes = INTR_COLOR_WHITE,
  82.     EELayerAttr = INTR_COLOR_WHITE,
  83.     EELayerDevice = INTR_COLOR_WHITE,
  84.     EELayerNotes = INTR_COLOR_WHITE,
  85.     EELayerNetNam = INTR_COLOR_WHITE,
  86.     EELayerPin = INTR_COLOR_WHITE;
  87. BooleanType
  88.     EEAutoPan = FALSE,
  89.     EEHVLineDrawing = TRUE,        /* Draw only horizontal/ vertical lines. */
  90.     EESubName = TRUE;
  91. IntrBBoxStruct
  92.     *EEActiveBBox = NULL;
  93. EEWindowStruct
  94.     *EEActiveWindow = NULL,                   /* Pointer to active window. */
  95.     *EEWindowsList = NULL;              /* List of all open windows/files. */
  96.  
  97. static char
  98.     *VersionStr =
  99.     "EEDraw    IBMPC "
  100.     EEDRAW_VERSION
  101.     "    Gershon Elber,  "
  102.     __DATE__ ",   " __TIME__ "\n"
  103.     "(C) Copyright 1989-91 Gershon Elber, Non commercial use only.\n";
  104. static char
  105.     *UsageStr = "Usage: EEDraw [-z] *[EEDrawFile.EED]\n";
  106. static int
  107.     ActiveWindowID = -1,
  108.     HelpWindowID = -1,
  109.     LayerWindowID = -1,
  110.     ShowWindowName = FALSE,
  111.     Allow256Colors = FALSE,
  112.     AllowAsyncEvents = TRUE,
  113.     MouseExists = FALSE,
  114.     JoyStickExists = FALSE,
  115.     ATKeyboard = FALSE,
  116.     MouseSensitivity = 32,
  117.     SaveBackMethod = 0,
  118.     GraphDriver = 0,
  119.     KeyBindingCount = 0,
  120.     LastKeyStroke = -1;
  121. static char
  122.     *LoadLibraryList = NULL,
  123.     *SaveBackPath = NULL,
  124.     *BGIDriverPath = NULL,
  125.     *SVGANameMode = NULL,
  126.     *LibrariesPathPtr = NULL,
  127.     InitialPath[FULL_PATH_LEN],
  128.     LibrariesPath[FULL_PATH_LEN];
  129. static IntrCursorShapeStruct Cursor;
  130. static IntrBBoxStruct ResizeBBox;
  131. static KeyBindingStruct KeyBindingList[MAX_KEY_BINDINGS];
  132.  
  133. static ConfigStruct SetUp[] =
  134. { { "Mouse",        &MouseExists,        SU_BOOLEAN_TYPE },
  135.   { "Joystick",        &JoyStickExists,    SU_BOOLEAN_TYPE },
  136.   { "ATKeyboard",    &ATKeyboard,        SU_BOOLEAN_TYPE },
  137.   { "AutoPan",        &EEAutoPan,        SU_BOOLEAN_TYPE },
  138.   { "SubName",          &EESubName,             SU_BOOLEAN_TYPE },
  139.   { "WindowName",    &ShowWindowName,    SU_BOOLEAN_TYPE },
  140.   { "HVLines",        &EEHVLineDrawing,    SU_BOOLEAN_TYPE },
  141.   { "Allow256Colors",   &Allow256Colors,    SU_BOOLEAN_TYPE },
  142.   { "AllowAsyncEvents", &AllowAsyncEvents,    SU_BOOLEAN_TYPE },
  143.   { "MouseSensitivity",    &MouseSensitivity,    SU_INTEGER_TYPE },
  144.   { "SnapDistance",    &EESnapDistance,    SU_INTEGER_TYPE },
  145.   { "SaveBackMethod",   &SaveBackMethod,    SU_INTEGER_TYPE },
  146.   { "GraphDriver",    &GraphDriver,        SU_INTEGER_TYPE },
  147.   { "RootFrameolor",    &EERootWndwFrameColor,  SU_INTEGER_TYPE },
  148.   { "RootForeColor",    &EERootWndwForeColor,   SU_INTEGER_TYPE },
  149.   { "RootBackColor",    &EERootWndwBackColor,   SU_INTEGER_TYPE },
  150.   { "RootXorColor",     &EERootWndwXorColor,    SU_INTEGER_TYPE },
  151.   { "ActvFrameColor",   &EEActvWndwFrameColor,  SU_INTEGER_TYPE },
  152.   { "ActvForeColor",    &EEActvWndwForeColor,   SU_INTEGER_TYPE },
  153.   { "ActvBackColor",    &EEActvWndwBackColor,   SU_INTEGER_TYPE },
  154.   { "PsvFrameColor",    &EEPsvWndwFrameColor,   SU_INTEGER_TYPE },
  155.   { "PsvForeColor",     &EEPsvWndwForeColor,    SU_INTEGER_TYPE },
  156.   { "PsvBackColor",     &EEPsvWndwBackColor,    SU_INTEGER_TYPE },
  157.   { "PopUpFrameColor",  &EEPopUpFrameColor,    SU_INTEGER_TYPE },
  158.   { "PopUpBackColor",   &EEPopUpBackColor,    SU_INTEGER_TYPE },
  159.   { "PopUpForeColor",   &EEPopUpForeColor,    SU_INTEGER_TYPE },
  160.   { "PopUpXorColor",    &EEPopUpXorColor,    SU_INTEGER_TYPE },
  161.   { "HighLightColor",   &EEHighLightColor,    SU_INTEGER_TYPE },
  162.   { "LayerWire",    &EELayerWire,        SU_INTEGER_TYPE },
  163.   { "LayerBus",        &EELayerBus,        SU_INTEGER_TYPE },
  164.   { "LayerGate",    &EELayerGate,        SU_INTEGER_TYPE },
  165.   { "LayerIEEE",    &EELayerIEEE,        SU_INTEGER_TYPE },
  166.   { "LayerPinFun",    &EELayerPinFun,        SU_INTEGER_TYPE },
  167.   { "LayerPinNum",    &EELayerPinNum,        SU_INTEGER_TYPE },
  168.   { "LayerPinNam",    &EELayerPinNam,        SU_INTEGER_TYPE },
  169.   { "LayerRefDes",    &EELayerRefDes,        SU_INTEGER_TYPE },
  170.   { "LayerAttr",    &EELayerAttr,        SU_INTEGER_TYPE },
  171.   { "LayerDevice",    &EELayerDevice,        SU_INTEGER_TYPE },
  172.   { "LayerNotes",    &EELayerNotes,        SU_INTEGER_TYPE },
  173.   { "LayerNetNam",    &EELayerNetNam,        SU_INTEGER_TYPE },
  174.   { "LayerPin",        &EELayerPin,        SU_INTEGER_TYPE },
  175.   { "FrameWidth",    &EEWindowsFrameWidth,   SU_INTEGER_TYPE },
  176.   { "BGIDriverPath",    &BGIDriverPath,        SU_STRING_TYPE },
  177.   { "SaveBackPath",    &SaveBackPath,        SU_STRING_TYPE },
  178.   { "SVGANameMode",    &SVGANameMode,        SU_STRING_TYPE },
  179.   { "Libraries",    &LoadLibraryList,    SU_STRING_TYPE },
  180.   { "LibrariesPath",    &LibrariesPathPtr,    SU_STRING_TYPE },
  181. };
  182. #define NUM_SET_UP    (sizeof(SetUp) / sizeof(ConfigStruct))
  183.  
  184. extern unsigned int _stklen = 16384;         /* Increase default stack size. */
  185.  
  186. static void MakeWindowActive(EEWindowStruct *Window, BooleanType Refresh);
  187. static void MakeFullPathName(char *FileName);
  188. static EEWindowStruct *LoadOneEEFile(char *FileName, BooleanType IsNew);
  189. static void HandleFileMenu(int Index);
  190. static void HandleWindowMenu(int Index);
  191. static void HandleDisplayMenu(int Index);
  192. static void HandleLibsMenu(int Index);
  193. static void HandleDrawMenu(int Index);
  194. static void HandleModifyMenu(int Index);
  195. static void HandleSameAgain(int KeyStroke);
  196. static void HandleKeyBindings(int KeyStroke);
  197. static void HandleStatusMenu(int Index);
  198. static int ReadKeyBindings(char *Name);
  199. static char *GetFileName(char *FullPathName);
  200. static void RootWndwRefreshFunc(int WindowID);
  201. static void LayerWndwRefreshFunc(int WindowID);
  202. static void HelpWndwRefreshFunc(int WindowID);
  203. static void DataWndwRefreshFunc(int WindowID);
  204.  
  205. static IntrIntFunc PDActionFuncs[] = {   /* Pull Down Functions to activate. */
  206.     HandleFileMenu,
  207.     HandleWindowMenu,
  208.     HandleDisplayMenu,
  209.     HandleLibsMenu,
  210.     HandleDrawMenu,
  211.     HandleModifyMenu,
  212.     HandleStatusMenu
  213. };
  214. static char *PDMenuStrs[] = {              /* Pull Down Menu Entry names: */
  215.     "File",
  216.     "Window",
  217.     "Display",
  218.     "Libs",
  219.     "Draw",
  220.     "Modify",
  221.     "Status"
  222. };
  223. #define PULL_DOWN_SIZE (sizeof(PDMenuStrs) / sizeof(char *))
  224.  
  225. static char *FilePUStrs[] = {
  226.     "LoadEEDFile        ",
  227.     "NewEEDFile         ",
  228.     "SaveAllEED         ",
  229.     "SaveEEDFile        ",
  230.     "SaveEEDAsOld       ",
  231.     "SaveEEDAsNew       ",
  232.     "SaveNetList        ",
  233.     "CloseEEDFile       ",
  234.     "ClearAll           ",
  235.     "Directory          ",
  236.     "ChangeDir          ",
  237.     "ShellToDos         ",
  238.     "ExitEEdraw         ",
  239. };
  240. #define FILE_POP_UP_SIZE (sizeof(FilePUStrs) / sizeof(char *))
  241. static IntrPopUpMenuStruct *FilePUMenu = NULL;
  242. static char *WindowPUStrs[] = {
  243.     "PopWindow            ",
  244.     "PushWindow           ",
  245.     "MoveWindow           ",
  246.     "ResizeWindow         ",
  247.     "FullSize             ",
  248.     "ShowName             ",
  249.     "MakeActive           ",
  250.     "NameActive           ",
  251.     "PanWindowLeft        ",
  252.     "PanWindowRight       ",
  253.     "PanWindowUp          ",
  254.     "PanWindowDown        "
  255. };
  256. #define WINDOW_POP_UP_SIZE (sizeof(WindowPUStrs) / sizeof(char *))
  257. static IntrPopUpMenuStruct *WindowPUMenu = NULL;
  258. static char *DisplayPUStrs[] = {
  259.     "ZoomOut         ",
  260.     "ZoomIn          ",
  261.     "ZoomReset       ",
  262.     "RedrawAll       "
  263. };
  264. #define DISPLAY_POP_UP_SIZE (sizeof(DisplayPUStrs) / sizeof(char *))
  265. static IntrPopUpMenuStruct *DisplayPUMenu = NULL;
  266. static char *LibsPUStrs[] = {
  267.     "LoadLibrary         ",
  268.     "LoadLibByName       ",
  269.     "FreeLibrary         ",
  270.     "ViewLibrary         ",
  271.     "DirLibrary          ",
  272.     "ChDirLibrary        "
  273. };
  274. #define LIBS_POP_UP_SIZE (sizeof(LibsPUStrs) / sizeof(char *))
  275. static IntrPopUpMenuStruct *LibsPUMenu = NULL;
  276. static char *DrawPUStrs[] = {
  277.     "DrawLine          ",
  278.     "DrawWire          ",    /* Draw Conection wire, ignore Current */
  279.                 /* Layer and enable status           */
  280.     "DrawBus           ",
  281.     "DrawConnect       ",
  282.     "DrawText          ",
  283.     "DrawLibItem       ",
  284.     "ChangeLayer       ",
  285.     "TglOneColor       ",
  286.     "SetOneColor       "
  287. };
  288. #define DRAW_POP_UP_SIZE (sizeof(DrawPUStrs) / sizeof(char *))
  289. static IntrPopUpMenuStruct *DrawPUMenu = NULL;
  290. static char *ModifyPUStrs[] = {
  291.     "ModifyMove         ",
  292.     "ModifyCopy         ",
  293.     "EditLibItem        ",
  294.     "ModifyDelete       ",
  295.     "ModifyUnDel        ",
  296.     "ModifyCut          ",
  297.     "ModifyPaste        ",
  298.     "ModifyDrop         "
  299. };
  300. #define MODIFY_POP_UP_SIZE (sizeof(ModifyPUStrs) / sizeof(char *))
  301. static IntrPopUpMenuStruct *ModifyPUMenu = NULL;
  302. static char *StatusPUStrs[] = {
  303.     "Help                ",
  304.     "GetMemoryFree       ",
  305.     "GetZoomFactor       ",
  306.     "SetDrawText         ",
  307.     "SetTextSize         ",
  308.     "SetAutoPan          ",
  309.     "SetHVLines          ",
  310.     "SetSnapFactor       ",
  311.     "SetLineWidth        "
  312. };
  313. #define STATUS_POP_UP_SIZE (sizeof(StatusPUStrs) / sizeof(char *))
  314. static IntrPopUpMenuStruct *StatusPUMenu = NULL;
  315.  
  316. static char **AllPUStrs[] = {
  317.     FilePUStrs,
  318.     WindowPUStrs,
  319.     DisplayPUStrs,
  320.     LibsPUStrs,
  321.     DrawPUStrs,
  322.     ModifyPUStrs,
  323.     StatusPUStrs
  324. };
  325. static int AllPUSizes[] = {
  326.     FILE_POP_UP_SIZE,
  327.     WINDOW_POP_UP_SIZE,
  328.     DISPLAY_POP_UP_SIZE,
  329.     LIBS_POP_UP_SIZE,
  330.     DRAW_POP_UP_SIZE,
  331.     MODIFY_POP_UP_SIZE,
  332.     STATUS_POP_UP_SIZE
  333. };
  334. #define ALL_POP_UP_SIZE (sizeof(AllPUStrs) / sizeof(char **))
  335.  
  336. /*****************************************************************************
  337. * Main routine - Read Parameter    line and do what you need...             *
  338. *****************************************************************************/
  339. void main(int argc, char **argv)
  340. {
  341.     int x, y;
  342.     IntrPullDownMenuStruct *MainPullDownMenu;
  343.  
  344.     getcwd(InitialPath, FULL_PATH_LEN);  /* Save where we were when started. */
  345.     strcpy(LibrariesPath, DEFAULT_LIB_DIR);
  346.  
  347.     if (strcmp(argv[1], "-z") == 0) {
  348.     fprintf(stderr, "%s%s", UsageStr, VersionStr);
  349.     MyExit(-1);
  350.     }
  351.  
  352.     SetUpCtrlBrk();
  353.     SetUpHardErr();
  354.  
  355.     Config(PROGRAM_NAME, SetUp, NUM_SET_UP); /* Read config. file if exists. */
  356.     SetColorSet();                 /* Set the baisc colour array */
  357.     if (LibrariesPathPtr != NULL) {
  358.     strcpy(LibrariesPath, LibrariesPathPtr);
  359.     MyFree((VoidPtr) LibrariesPathPtr);
  360.     };
  361.  
  362.     /* Read the key binding file and initialize the main menu accordingly: */
  363.     if (!ReadKeyBindings(PROGRAM_NAME)) MyExit(-1);
  364.  
  365.     Cursor.CursorType = INTR_CURSOR_ARROW;
  366.     IntrSetCursorType(&Cursor);
  367.  
  368.     if (SVGANameMode != NULL && strlen(SVGANameMode) > 0)
  369.     GRInstallSVGA(SVGANameMode);
  370.  
  371.     if (BGIDriverPath != NULL && strlen(BGIDriverPath) > 0)
  372.         GRSetBGIPath(BGIDriverPath);
  373.  
  374.     GRSetDefaultDriver(GraphDriver);
  375.  
  376.     IntrSetSaveBackPath(SaveBackPath);
  377.     IntrSetSaveBackMethod(SaveBackMethod);
  378.  
  379.     IntrSetMouseSensitivity(MouseSensitivity);
  380.     IntrSetAtKeyboard(ATKeyboard);
  381.  
  382.     IntrAllow256Colors(Allow256Colors);
  383.     IntrSetAsyncEventMode(AllowAsyncEvents);
  384.  
  385.     /* SeedLayers();              /* seed the layer structures */
  386.  
  387.     IntrInit();                  /* Initialize the interaction library. */
  388.  
  389.     IntrSetInputDevice(INTR_INPT_DEVICE_KEYBOARD |
  390.                    (MouseExists ? INTR_INPT_DEVICE_MOUSE : 0) |
  391.                        (JoyStickExists ? INTR_INPT_DEVICE_JOYSTICK : 0));
  392.                
  393.     EEListNumDisplayed = GRScreenMaxY / 20;
  394.  
  395.     MainPullDownMenu = IntrPullDownMenuCreate(PDMenuStrs, 0, PULL_DOWN_SIZE,
  396.                               PDActionFuncs,
  397.                                               EERootWndwFrameColor,
  398.                                               EERootWndwBackColor,
  399.                                               EERootWndwForeColor,
  400.                                               EERootWndwXorColor,
  401.                                               EEWindowsFrameWidth);
  402.  
  403.     ResizeBBox.Xmin = EEWindowsFrameWidth;
  404.     ResizeBBox.Xmax = GRScreenMaxX - EEWindowsFrameWidth;
  405.     ResizeBBox.Ymin = IntrWndwGetHeaderHeight("M", EEWindowsFrameWidth) +
  406.                                 EEWindowsFrameWidth + 2;
  407.     ResizeBBox.Ymax = GRScreenMaxY - EEWindowsFrameWidth;
  408.  
  409.     /* Create and map to screen the root back ground window. */
  410.     EERootWindowID = IntrWndwCreate(NULL, EEWindowsFrameWidth, &ResizeBBox,
  411.                 EERootWndwFrameColor, EERootWndwBackColor, NULL,
  412.                                 MainPullDownMenu, RootWndwRefreshFunc);
  413.     IntrWndwSetZoom(EERootWindowID, DEFAULT_ZOOM_FACTOR);
  414.     IntrWndwPop(EERootWindowID, TRUE, FALSE);
  415.  
  416.     ResizeBBox.Xmin += IntrWndwScrollBarWidth();
  417.     if (ShowWindowName)
  418.     ResizeBBox.Ymin += IntrWndwGetHeaderHeight("M", EEWindowsFrameWidth) + 2;
  419.     ResizeBBox.Ymax -= IntrWndwScrollBarWidth();
  420.     IntrWndwSetResizeBBox(&ResizeBBox);       /* Set bounds to window resizing. */
  421.  
  422.     FilePUMenu = IntrPopUpMenuCreate(NULL, FilePUStrs, 0, FILE_POP_UP_SIZE,
  423.                          EERootWndwFrameColor, EERootWndwBackColor,
  424.                                      EERootWndwForeColor, EERootWndwXorColor,
  425.                                      EEWindowsFrameWidth, &Cursor);
  426.     WindowPUMenu = IntrPopUpMenuCreate(NULL, WindowPUStrs, 0, WINDOW_POP_UP_SIZE,
  427.                          EERootWndwFrameColor, EERootWndwBackColor,
  428.                                      EERootWndwForeColor, EERootWndwXorColor,
  429.                                      EEWindowsFrameWidth, &Cursor);
  430.     DisplayPUMenu = IntrPopUpMenuCreate(NULL, DisplayPUStrs, 0, DISPLAY_POP_UP_SIZE,
  431.                     EERootWndwFrameColor, EERootWndwBackColor,
  432.                                         EERootWndwForeColor, EERootWndwXorColor,
  433.                                         EEWindowsFrameWidth, &Cursor);
  434.     LibsPUMenu = IntrPopUpMenuCreate(NULL, LibsPUStrs, 0, LIBS_POP_UP_SIZE,
  435.                          EERootWndwFrameColor, EERootWndwBackColor,
  436.                                      EERootWndwForeColor, EERootWndwXorColor,
  437.                                      EEWindowsFrameWidth, &Cursor);
  438.     DrawPUMenu = IntrPopUpMenuCreate(NULL, DrawPUStrs, 0, DRAW_POP_UP_SIZE,
  439.                          EERootWndwFrameColor, EERootWndwBackColor,
  440.                                      EERootWndwForeColor, EERootWndwXorColor,
  441.                                      EEWindowsFrameWidth, &Cursor);
  442.     ModifyPUMenu = IntrPopUpMenuCreate(NULL, ModifyPUStrs, 0, MODIFY_POP_UP_SIZE,
  443.                            EERootWndwFrameColor, EERootWndwBackColor,
  444.                                        EERootWndwForeColor, EERootWndwXorColor,
  445.                                        EEWindowsFrameWidth, &Cursor);
  446.     StatusPUMenu = IntrPopUpMenuCreate(NULL, StatusPUStrs, 0, STATUS_POP_UP_SIZE,
  447.                            EERootWndwFrameColor, EERootWndwBackColor,
  448.                                        EERootWndwForeColor, EERootWndwXorColor,
  449.                                        EEWindowsFrameWidth, &Cursor);
  450.  
  451.     if (LoadLibraryList != NULL) {
  452.     LoadLibraries(LoadLibraryList);
  453.     MyFree((VoidPtr) LoadLibraryList);
  454.     LoadLibraryList = NULL;
  455.     }
  456.  
  457.     /* Load All files specified in the command line. */
  458.     while (argc-- > 1)
  459.         LoadOneEEFile(*++argv, FALSE);
  460.  
  461.     /* Query events forever. From this point everything is events driven     */
  462.     /* and we need do nothing beyond this infinite event query.             */
  463.     while (TRUE) {
  464.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  465.         if (IntrGetEventWait(&x, &y) == INTR_EVNT_MIDDLE_BUTTON)
  466.         HandleSameAgain(0);
  467.     }
  468. }
  469.  
  470. /*****************************************************************************
  471. * Routine to handle the FILE pull down sub menu.                 *
  472. *****************************************************************************/
  473. static void MakeWindowActive(EEWindowStruct *Window, BooleanType Refresh)
  474. {
  475.     if (EEActiveWindow == Window) return;
  476.  
  477.     /* If there is current active window - inactivate it. */
  478.     if (ActiveWindowID >= 0) {
  479.     IntrWndwSetFrameColor(EEActiveWindow -> IntrLibWindowID,
  480.                   EEPsvWndwFrameColor);
  481.     IntrWndwSetBackGroundColor(EEActiveWindow -> IntrLibWindowID,
  482.                        EEPsvWndwBackColor);
  483.         IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, TRUE,
  484.                INTR_SCRLBAR_LEFT, EEPsvWndwForeColor);
  485.         IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, FALSE,
  486.                INTR_SCRLBAR_BOTTOM, EEPsvWndwForeColor);
  487.     if (Refresh)
  488.             IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  489.     }
  490.  
  491.     EEActiveWindow = Window;
  492.     ActiveWindowID = EEActiveWindow -> IntrLibWindowID;
  493.     EEActiveBBox = IntrWndwGetBBox(ActiveWindowID);
  494.     IntrWndwSetFrameColor(EEActiveWindow -> IntrLibWindowID,
  495.               EEActvWndwFrameColor);
  496.     IntrWndwSetBackGroundColor(EEActiveWindow -> IntrLibWindowID,
  497.                    EEActvWndwBackColor);
  498.     IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, TRUE,
  499.                INTR_SCRLBAR_LEFT, EEActvWndwForeColor);
  500.     IntrWndwSetScrlBar(EEActiveWindow -> IntrLibWindowID, FALSE,
  501.                INTR_SCRLBAR_BOTTOM, EEActvWndwForeColor);
  502.     if (Refresh)
  503.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  504. }
  505.  
  506. /*****************************************************************************
  507. * Routine to make sure the cursor is positioned in the active window.        *
  508. *****************************************************************************/
  509. void PutCursorInActiveWindow(void)
  510. {
  511.     if (EEActiveBBox -> Xmin > GRCurrentCursorX ||
  512.     EEActiveBBox -> Xmax < GRCurrentCursorX ||
  513.     EEActiveBBox -> Ymin > GRCurrentCursorY ||
  514.     EEActiveBBox -> Ymax < GRCurrentCursorY) {
  515.     GRCurrentCursorX = (EEActiveBBox -> Xmin + EEActiveBBox -> Xmax) / 2;
  516.     GRCurrentCursorY = (EEActiveBBox -> Ymin + EEActiveBBox -> Ymax) / 2;
  517.     }
  518. }
  519.  
  520. /*****************************************************************************
  521. * Routine to expand a file name to be a full path if necessary.             *
  522. *****************************************************************************/
  523. static void MakeFullPathName(char *FileName)
  524. {
  525.     int Mask;
  526.     char Drive[3], Dir[66], Name[9], Ext[5];
  527.  
  528.     Mask = fnsplit(FileName, Drive, Dir, Name, Ext);
  529.  
  530.     if (!(Mask & DRIVE)) {
  531.     Drive[0] = getdisk() + 'A';
  532.     Drive[1] = ':';
  533.     Drive[2] = 0;
  534.     }
  535.     if (!(Mask & DIRECTORY)) {
  536.         strcpy(Dir, "\\");
  537.         getcurdir(Drive[0] - 'A' + 1, &Dir[1]);
  538.     }
  539.  
  540.     fnmerge(FileName, Drive, Dir, Name, Ext);
  541.     strlwr(FileName);
  542. }
  543.  
  544. /*****************************************************************************
  545. * Routine to handle file loading. If given file name is NULL the name is     *
  546. * queried (within LoadEEFile).                             *
  547. * However if IsNew then no file is loaded.                     *
  548. *****************************************************************************/
  549. static EEWindowStruct *LoadOneEEFile(char *FileName, BooleanType IsNew)
  550. {
  551.     EEWindowStruct
  552.         *Window = (EEWindowStruct *) MyMalloc(sizeof(EEWindowStruct));
  553.  
  554.     if (FileName != NULL)
  555.     strcpy(Window -> FileName, FileName);
  556.     else
  557.     Window -> FileName[0] = 0;
  558.  
  559.     SeedLayers(Window);
  560.     Window -> EEDrawList = NULL;
  561.     Window -> IntrLibWindowID = -1;
  562.     Window -> Modified = FALSE;
  563.     if (IsNew || LoadEEFile(Window)) {
  564.     if (strlen(Window -> FileName) == 0)
  565.         strcpy(Window -> FileName, "noname.eed");
  566.         /* Expand the file name to full path if necessary: */
  567.     MakeFullPathName(Window ->FileName);
  568.  
  569.         Window -> PageXSize = PAGE_A4_XSIZE;
  570.         Window -> PageYSize = PAGE_A4_YSIZE;
  571.     Window -> IsFullSize = FALSE;
  572.     Window -> IntrLibWindowID =
  573.             IntrWndwCreate(ShowWindowName ? Window -> FileName : NULL,
  574.                        EEWindowsFrameWidth, &ResizeBBox,
  575.                EEActvWndwFrameColor, EEActvWndwBackColor,
  576.                            NULL, NULL, DataWndwRefreshFunc);
  577.         /* ShowStatus(Window); */
  578.         IntrWndwSetScrlBar(Window -> IntrLibWindowID, TRUE,
  579.                INTR_SCRLBAR_LEFT, EEActvWndwForeColor);
  580.         IntrWndwSetScrlBar(Window -> IntrLibWindowID, FALSE,
  581.                INTR_SCRLBAR_BOTTOM, EEActvWndwForeColor);
  582.     IntrWndwSetZoom(Window -> IntrLibWindowID, DEFAULT_ZOOM_FACTOR);
  583.     IntrWndwSetPanning(Window -> IntrLibWindowID,
  584.                    DEFAULT_INV_ZOOM(Window -> PageXSize) / 2,
  585.                            DEFAULT_INV_ZOOM(Window -> PageYSize) / 2);
  586.         Window -> Pnext = EEWindowsList;
  587.         EEWindowsList = Window;
  588.         IntrWndwResize(Window -> IntrLibWindowID, FALSE);
  589.         MakeWindowActive(Window, FALSE);
  590.         ShowStatus(Window,0);
  591.         return Window;
  592.     }
  593.     else {
  594.     MyFree((VoidPtr) Window);
  595.     return NULL;
  596.     }
  597. }
  598.  
  599. /*****************************************************************************
  600. * Routine to handle the FILE pull down sub menu.                 *
  601. *****************************************************************************/
  602. static void HandleFileMenu(int Index)
  603. {
  604.     int NumOfFiles, WindowID;
  605.     char Line[LINE_LEN], Buffer[LINE_LEN];
  606.     FileNameType *FileNames;
  607.     EEWindowStruct *TWindow, *Window;
  608.  
  609.     if (Index >= 0) {
  610.     if (IntrPopUpMenu(FilePUMenu, INTR_WNDW_PULL_DOWN))
  611.         Index = FilePUMenu -> SelectedIndex;
  612.         else
  613.             Index = -1;
  614.     }
  615.     else
  616.     Index += DIRECT_CALL_INDEX_OFFSET;
  617.  
  618.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  619.  
  620.     switch(Index) {
  621.         case 0: /* Load EED File */
  622.         LoadOneEEFile(NULL, FALSE);
  623.             break;
  624.         case 1: /* New EED File */
  625.         LoadOneEEFile(NULL, TRUE);
  626.             break;
  627.     case 2: /* Save All EED */
  628.             for (Window = EEWindowsList;
  629.                  Window != NULL;
  630.                  Window = Window -> Pnext)
  631.                 if (Window -> Modified) {
  632.                     IntrDrawMessage(Window -> FileName, EEPopUpForeColor,
  633.                                         EEPopUpBackColor);
  634.                     if (SaveEEFile(FILE_SAVE_AS, Window)) {
  635.                         Window -> Modified = FALSE;
  636.                     
  637.                     }
  638.             IntrEraseMessage();
  639.                 }
  640.             if (ShowWindowName){
  641.         ShowStatus(Window,0);
  642.         IntrWndwRedrawAll();
  643.         }
  644.         break;
  645.     case 3: /* Save EED As */
  646.         if (ActiveWindowID < 0) {
  647.         IntrQueryContinue("No active window to save.",
  648.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  649.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  650.               INTR_WNDW_PLACE_CENTER);
  651.         break;
  652.         }
  653.         if (!EEActiveWindow -> Modified) {
  654.         IntrQueryContinue("Active file has not been modified",
  655.                   EEPopUpFrameColor, EEPopUpBackColor,
  656.                   EEPopUpForeColor, EEPopUpXorColor,
  657.                   EEWindowsFrameWidth, &Cursor,
  658.                   INTR_WNDW_PLACE_CENTER);
  659.         break;
  660.         }
  661.         if (SaveEEFile(FILE_SAVE_AS, EEActiveWindow)) {
  662.         EEActiveWindow -> Modified = FALSE;
  663.      
  664.         }
  665.         break;
  666.     case 4: /* Save EED Old */
  667.         if (ActiveWindowID < 0) {
  668.         IntrQueryContinue("No active window to save.",
  669.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  670.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  671.               INTR_WNDW_PLACE_CENTER);
  672.         break;
  673.         }
  674.         if (SaveEEFile(FILE_SAVE_OLD, EEActiveWindow)) {
  675.         EEActiveWindow -> Modified = FALSE;
  676.          
  677.  
  678.         /* Expand the file name to full path: */
  679.         MakeFullPathName(EEActiveWindow -> FileName);
  680.  
  681.         if (ShowWindowName) {
  682.             IntrWndwSetName(EEActiveWindow -> IntrLibWindowID,
  683.                     EEActiveWindow -> FileName);
  684.             IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  685.         }
  686.         }
  687.         break;
  688.     case 5: /* Save EED New */
  689.         if (ActiveWindowID < 0) {
  690.         IntrQueryContinue("No active window to save.",
  691.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  692.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  693.               INTR_WNDW_PLACE_CENTER);
  694.         break;
  695.         }
  696.         if (SaveEEFile(FILE_SAVE_NEW, EEActiveWindow)) {
  697.         EEActiveWindow -> Modified = FALSE;
  698.          
  699.  
  700.         /* Expand the file name to full path: */
  701.         MakeFullPathName(EEActiveWindow -> FileName);
  702.  
  703.         if (ShowWindowName) {
  704.             IntrWndwSetName(EEActiveWindow -> IntrLibWindowID,
  705.                     EEActiveWindow -> FileName);
  706.             IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  707.         }
  708.         }
  709.         break;
  710.     case 6: /* Save Net List */
  711.         if (ActiveWindowID < 0) {
  712.         IntrQueryContinue("No active window to save.",
  713.               EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  714.               EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  715.               INTR_WNDW_PLACE_CENTER);
  716.         break;
  717.         }
  718.         SaveNetList(EEActiveWindow);
  719.         break;
  720.     case 7: /* Close EED File */
  721.         if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  722.         for (Window = EEWindowsList;
  723.              Window != NULL;
  724.              Window = Window -> Pnext)
  725.             if (Window -> IntrLibWindowID == WindowID) break;
  726.         if (Window == NULL) break;
  727.  
  728.         if (Window -> Modified &&
  729.             !IntrQueryYesNo("Window modified - delete?",
  730.             EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  731.             EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  732.             INTR_WNDW_PLACE_CENTER))
  733.             break;
  734.  
  735.         /* Delete the window from window list */
  736.         if (EEWindowsList != Window) {
  737.             for (TWindow = EEWindowsList;
  738.              TWindow -> Pnext != Window;
  739.              TWindow = TWindow -> Pnext);
  740.             TWindow -> Pnext = TWindow -> Pnext -> Pnext;
  741.         }
  742.         else
  743.             EEWindowsList = EEWindowsList -> Pnext;
  744.  
  745.         CloseEEDFile(Window);
  746.  
  747.         if (Window == EEActiveWindow) {
  748.             ActiveWindowID = -1;
  749.             EEActiveWindow = NULL;
  750.             if (EEWindowsList != NULL)
  751.             MakeWindowActive(EEWindowsList, FALSE);
  752.         }
  753.         IntrWndwRedrawAll();
  754.         }
  755.         break;
  756.     case 8: /* Clear All */
  757.         if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  758.         for (Window = EEWindowsList;
  759.              Window != NULL;
  760.              Window = Window -> Pnext)
  761.             if (Window -> IntrLibWindowID == WindowID) break;
  762.         if (Window == NULL) break;
  763.  
  764.         if (ClearDrawList(Window)) {
  765.             Window -> Modified = TRUE;
  766.             ShowStatus(Window,0);
  767.         }
  768.         }
  769.         break;
  770.     case 9: /* Directory */
  771.         if ((FileNames = GetFileNamesDir("*.*", ".", &NumOfFiles))
  772.                                 != NULL) {
  773.         qsort(FileNames, NumOfFiles, sizeof(FileNameType),
  774.               (int (*)(const void *, const void *)) strcmp);
  775.         IntrQueryList("Directory", (char **) FileNames,
  776.              sizeof(FileNameType), NumOfFiles, EEListNumDisplayed,
  777.              EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  778.              EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  779.              INTR_WNDW_PLACE_CENTER);
  780.         MyFree((VoidPtr) FileNames);
  781.         }
  782.         break;
  783.     case 10: /* New Dir */
  784.         getcwd(Line, LINE_LEN - 1);
  785.         sprintf(Buffer, "New dir (%s):", Line);
  786.         IntrQueryLine(Buffer, Line, LINE_LEN - 1, EEPopUpFrameColor,
  787.               EEPopUpBackColor, EEPopUpForeColor,
  788.               EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  789.         if (ChangeDir(Line) != CD_OK) {
  790.         GRTone(1400, 100);             /* Do some noise... */
  791.         GRTone( 400, 100);
  792.         }
  793.         break;
  794.     case 11: /* Push to DOS */
  795.         /* Look for unsaved file and if found one - issue a warning. */
  796.         for (Window = EEWindowsList;
  797.          Window != NULL;
  798.          Window = Window -> Pnext)
  799.         if (Window -> Modified) {
  800.             if (IntrQueryYesNo("Not all files are saved, save first?",
  801.                        EEPopUpFrameColor, EEPopUpBackColor,
  802.                        EEPopUpForeColor, EEPopUpXorColor,
  803.                        EEWindowsFrameWidth, &Cursor,
  804.                        INTR_WNDW_PLACE_CENTER)) {
  805.             HandleFileMenu(2 - DIRECT_CALL_INDEX_OFFSET);
  806.             }
  807.             break;
  808.         }
  809.  
  810.         DosSystem();
  811.         break;
  812.     case 12: /* Exit */
  813.         /* Look for unsaved file and if found one - issue a warning. */
  814.         for (Window = EEWindowsList;
  815.          Window != NULL;
  816.          Window = Window -> Pnext)
  817.         if (Window -> Modified) {
  818.             if (IntrQueryYesNo("Not all files are saved, save first?",
  819.                        EEPopUpFrameColor, EEPopUpBackColor,
  820.                        EEPopUpForeColor, EEPopUpXorColor,
  821.                        EEWindowsFrameWidth, &Cursor,
  822.                        INTR_WNDW_PLACE_CENTER)) {
  823.             HandleFileMenu(2 - DIRECT_CALL_INDEX_OFFSET);
  824.             }
  825.             break;
  826.         }
  827.  
  828.         IntrInputFlush();      /* Make sure we do not exit accidentally. */
  829.         if (IntrQueryYesNo("Exit EEDRAW", EEPopUpFrameColor,
  830.                    EEPopUpBackColor, EEPopUpForeColor,
  831.                    EEPopUpXorColor, EEWindowsFrameWidth,
  832.                    &Cursor, INTR_WNDW_PLACE_CENTER))
  833.         MyExit(0);
  834.     }
  835. }
  836.  
  837. /*****************************************************************************
  838. * Routine to handle the WINDOW pull down sub menu.                 *
  839. *****************************************************************************/
  840. static void HandleWindowMenu(int Index)
  841. {
  842.     int i, WindowID;
  843.     char **Names;
  844.     EEWindowStruct *Window;
  845.     IntrBBoxStruct *BBox;
  846.  
  847.     if (ActiveWindowID < 0 && HelpWindowID < 0) {
  848.     IntrQueryContinue("No windows to work on.",
  849.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  850.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  851.                           INTR_WNDW_PLACE_CENTER);
  852.         return;
  853.     }
  854.  
  855.     if (Index >= 0) {
  856.     if (IntrPopUpMenu(WindowPUMenu, INTR_WNDW_PULL_DOWN))
  857.         Index = WindowPUMenu -> SelectedIndex;
  858.         else
  859.             Index = -1;
  860.     }
  861.     else
  862.     Index += DIRECT_CALL_INDEX_OFFSET;
  863.  
  864.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  865.  
  866.     switch(Index) {
  867.     case 0: /* Pop */
  868.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID)
  869.                 IntrWndwPop(WindowID, TRUE, FALSE);
  870.             break;
  871.     case 1: /* Push */
  872.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  873.                 IntrWndwPush(WindowID, FALSE);
  874.                 IntrWndwPush(EERootWindowID, TRUE);
  875.             }
  876.             break;
  877.         case 2: /* Move. */
  878.         if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID)
  879.          IntrWndwMove(WindowID, TRUE);
  880.             break;
  881.         case 3: /* Resize. */
  882.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  883.         if (WindowID == HelpWindowID) {
  884.             /* Set bounds to help window resizing (no bottom scrlbar). */
  885.                     ResizeBBox.Ymax += IntrWndwScrollBarWidth();
  886.             IntrWndwSetResizeBBox(&ResizeBBox);
  887.         }
  888.  
  889.                 IntrWndwResize(WindowID, TRUE);
  890.  
  891.         if (WindowID == HelpWindowID) {
  892.             /* Set bounds back to default window resizing. */
  893.                     ResizeBBox.Ymax -= IntrWndwScrollBarWidth();
  894.             IntrWndwSetResizeBBox(&ResizeBBox);
  895.                 }
  896.             }
  897.         break;
  898.         case 4: /* Full Size. */
  899.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID)
  900.             for (Window = EEWindowsList;
  901.              Window != NULL;
  902.                  Window = Window -> Pnext)
  903.                     if (WindowID == Window -> IntrLibWindowID) {
  904.                         if (Window -> IsFullSize) {
  905.                 IntrWndwSetBBox(WindowID, &Window -> BBox);
  906.                 IntrWndwRedrawAll();
  907.                         }
  908.                         else {
  909.                 BBox = IntrWndwGetBBox(WindowID);
  910.                             Window -> BBox = *BBox;
  911.                 IntrWndwSetBBox(WindowID, &ResizeBBox);
  912.                 IntrWndwPop(WindowID, TRUE, FALSE);
  913.                         }
  914.                         Window -> IsFullSize = !Window -> IsFullSize;
  915.                         break;
  916.                     }
  917.             break;
  918.         case 5: /* Show Window Name. */
  919.             /* The ! below on both sides guarantee boolean values only... */
  920.         if (!ShowWindowName !=
  921.                 !IntrQueryYesNo("Show Window Names", EEPopUpFrameColor,
  922.                            EEPopUpBackColor, EEPopUpForeColor,
  923.                                EEPopUpXorColor, EEWindowsFrameWidth,
  924.                                &Cursor, INTR_WNDW_PLACE_CENTER)) {
  925.         ShowWindowName = !ShowWindowName;
  926.  
  927.         if (ShowWindowName)
  928.             ResizeBBox.Ymin += IntrWndwGetHeaderHeight("M",
  929.                                           EEWindowsFrameWidth) + 2;
  930.         else
  931.             ResizeBBox.Ymin -= IntrWndwGetHeaderHeight("M",
  932.                               EEWindowsFrameWidth) + 2;
  933.         IntrWndwSetResizeBBox(&ResizeBBox);
  934.  
  935.             for (Window = EEWindowsList;
  936.                  Window != NULL;
  937.                  Window = Window -> Pnext) {
  938.                     /* Make sure min. Y does not cover the Pull Down Menu. */
  939.             BBox = IntrWndwGetBBox(Window -> IntrLibWindowID);
  940.                     if (BBox -> Ymin < ResizeBBox.Ymin)
  941.             BBox -> Ymin = ResizeBBox.Ymin;
  942.  
  943.             IntrWndwSetName(Window -> IntrLibWindowID,
  944.                     ShowWindowName ? Window -> FileName : NULL);
  945.         }
  946.                 if (HelpWindowID >= 0) {
  947.             BBox = IntrWndwGetBBox(HelpWindowID);
  948.                     if (BBox -> Ymin < ResizeBBox.Ymin)
  949.                 BBox -> Ymin = ResizeBBox.Ymin;
  950.  
  951.             IntrWndwSetName(HelpWindowID,
  952.                     ShowWindowName ? "Help" : NULL);
  953.                 }
  954.  
  955.                 IntrWndwRedrawAll();
  956.             }
  957.             break;
  958.         case 6: /* Make Window Active. */
  959.             if ((WindowID = IntrWndwPick()) > 0 && WindowID != EERootWindowID) {
  960.             for (Window = EEWindowsList;
  961.                  Window != NULL;
  962.                  Window = Window -> Pnext)
  963.                     if (WindowID == Window -> IntrLibWindowID) {
  964.                         MakeWindowActive(Window, TRUE);
  965.                         break;
  966.                     }
  967.         }
  968.             break;
  969.         case 7: /* Make Window Active by Name. */
  970.         for (Window = EEWindowsList, i = 0;    /* Find how many windows. */
  971.                  Window != NULL;
  972.              Window = Window -> Pnext, i++);
  973.         Names = (char **) MyMalloc(sizeof(char *) * i);
  974.         for (Window = EEWindowsList, i = 0;   /* Prepare array of names. */
  975.          Window != NULL;
  976.              Window = Window -> Pnext)
  977.                 Names[i++] = GetFileName(Window -> FileName);
  978.         i = IntrQueryList("File Names", Names, 0, i, EEListNumDisplayed,
  979.                          EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  980.                          EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  981.                          INTR_WNDW_PLACE_CENTER);
  982.             MyFree((VoidPtr) Names);
  983.             if (i >= 0) {      /* If was selection - find window and select. */
  984.         for (Window = EEWindowsList;
  985.                      i-- > 0;
  986.                  Window = Window -> Pnext);
  987.                 MakeWindowActive(Window, TRUE);
  988.             }
  989.         break;
  990.     case 8: /* Pan left */
  991.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID,
  992.                   (GRInvMapX(EEActiveBBox -> Xmin) -
  993.                                GRInvMapX(EEActiveBBox -> Xmax)) / 2, 0);
  994.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  995.         break;
  996.     case 9: /* Pan right */
  997.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID,
  998.                   (GRInvMapX(EEActiveBBox -> Xmax) -
  999.                                GRInvMapX(EEActiveBBox -> Xmin)) / 2, 0);
  1000.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  1001.         break;
  1002.     case 10: /* Pan up */
  1003.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID, 0,
  1004.                   (GRInvMapX(EEActiveBBox -> Ymin) -
  1005.                                GRInvMapX(EEActiveBBox -> Ymax)) / 2);
  1006.  
  1007.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  1008.         break;
  1009.     case 11: /* Pan down */
  1010.             IntrWndwUpdatePanning(EEActiveWindow -> IntrLibWindowID, 0,
  1011.                   (GRInvMapX(EEActiveBBox -> Ymax) -
  1012.                                GRInvMapX(EEActiveBBox -> Ymin)) / 2);
  1013.         IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  1014.         break;
  1015.  
  1016.     }
  1017. }
  1018.  
  1019. /*****************************************************************************
  1020. * Routine to handle the DISPLAY pull down sub menu.                 *
  1021. *****************************************************************************/
  1022. static void HandleDisplayMenu(int Index)
  1023. {
  1024.     if (ActiveWindowID < 0) {
  1025.     IntrQueryContinue("No active window to work on.",
  1026.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1027.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1028.                           INTR_WNDW_PLACE_CENTER);
  1029.         return;
  1030.     }
  1031.  
  1032.     if (Index >= 0) {
  1033.     if (IntrPopUpMenu(DisplayPUMenu, INTR_WNDW_PULL_DOWN))
  1034.         Index = DisplayPUMenu -> SelectedIndex;
  1035.         else
  1036.             Index = -1;
  1037.     }
  1038.     else
  1039.     Index += DIRECT_CALL_INDEX_OFFSET;
  1040.  
  1041.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  1042.  
  1043.     switch(Index) {
  1044.     case 0:
  1045.         if (IntrWndwGetZoomFactor(ActiveWindowID) -
  1046.                 DEFAULT_ZOOM_FACTOR >= 4)
  1047.             IntrQueryContinue("Zoom value is out of range",
  1048.                       EEPopUpFrameColor, EEPopUpBackColor,
  1049.                                   EEPopUpForeColor, EEPopUpXorColor,
  1050.                                   EEWindowsFrameWidth, &Cursor,
  1051.                                   INTR_WNDW_PLACE_CENTER);
  1052.             else {
  1053.         IntrWndwUpdateZoom(ActiveWindowID, 1);
  1054.         IntrWndwPop(ActiveWindowID, TRUE, FALSE);
  1055.             }
  1056.         break;
  1057.         case 1:
  1058.         if (IntrWndwGetZoomFactor(ActiveWindowID) -
  1059.                 DEFAULT_ZOOM_FACTOR <= -4)
  1060.             IntrQueryContinue("Zoom value is out of range",
  1061.                       EEPopUpFrameColor, EEPopUpBackColor,
  1062.                                   EEPopUpForeColor, EEPopUpXorColor,
  1063.                   EEWindowsFrameWidth, &Cursor,
  1064.                                   INTR_WNDW_PLACE_CENTER);
  1065.             else {
  1066.         IntrWndwUpdateZoom(ActiveWindowID, -1);
  1067.         IntrWndwPop(ActiveWindowID, TRUE, FALSE);
  1068.             }
  1069.         break;
  1070.     case 2:
  1071.         IntrWndwSetZoom(ActiveWindowID, DEFAULT_ZOOM_FACTOR);
  1072.         IntrWndwPop(ActiveWindowID, TRUE, FALSE);
  1073.         break;
  1074.     case 3:
  1075.         IntrWndwRedrawAll();
  1076.         break;
  1077.     }
  1078. }
  1079.  
  1080. /*****************************************************************************
  1081. * Routine to handle the LIBS pull down sub menu.                 *
  1082. *****************************************************************************/
  1083. static void HandleLibsMenu(int Index)
  1084. {
  1085.     int NumOfFiles;
  1086.     char Line[LINE_LEN], Buffer[LINE_LEN], CrntPath[FULL_PATH_LEN];
  1087.     FileNameType *FileNames;
  1088.  
  1089.     if (Index >= 0) {
  1090.     if (IntrPopUpMenu(LibsPUMenu, INTR_WNDW_PULL_DOWN))
  1091.         Index = LibsPUMenu -> SelectedIndex;
  1092.     else
  1093.         Index = -1;
  1094.     }
  1095.     else
  1096.     Index += DIRECT_CALL_INDEX_OFFSET;
  1097.  
  1098.     GRSetViewPort(0, 0, GRScreenMaxX, GRScreenMaxY);
  1099.  
  1100.     getcwd(CrntPath, FULL_PATH_LEN - 1);
  1101.     ChangeDir(LibrariesPath);
  1102.  
  1103.     switch(Index) {
  1104.     case 0:
  1105.         LoadLibrary();
  1106.         break;
  1107.     case 1:
  1108.         Line[0] = 0;
  1109.         IntrQueryLine("New library(ies) to load:", Line, LINE_LEN - 1,
  1110.               EEPopUpFrameColor,
  1111.               EEPopUpBackColor, EEPopUpForeColor,
  1112.               EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1113.         LoadLibraries(Line);
  1114.         break;
  1115.     case 2:
  1116.         FreeLibrary(NULL);
  1117.         break;
  1118.     case 3:
  1119.         ViewLibrary();
  1120.         break;
  1121.     case 4:
  1122.         if ((FileNames = GetFileNamesDir("*.lib", ".", &NumOfFiles))
  1123.                                 != NULL) {
  1124.         qsort(FileNames, NumOfFiles, sizeof(FileNameType),
  1125.               (int (*)(const void *, const void *)) strcmp);
  1126.         IntrQueryList("Directory", (char **) FileNames,
  1127.              sizeof(FileNameType), NumOfFiles, EEListNumDisplayed,
  1128.              EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1129.              EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1130.              INTR_WNDW_PLACE_CENTER);
  1131.         MyFree((VoidPtr) FileNames);
  1132.         }
  1133.         break;
  1134.     case 5:
  1135.         strcpy(Line, LibrariesPath);
  1136.         sprintf(Buffer, "New lib dir (%s):", LibrariesPath);
  1137.         IntrQueryLine(Buffer, Line, LINE_LEN - 1, EEPopUpFrameColor,
  1138.               EEPopUpBackColor, EEPopUpForeColor,
  1139.               EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1140.         if (ChangeDir(Line) != CD_OK) {
  1141.         GRTone(1400, 100);             /* Do some noise... */
  1142.         GRTone( 400, 100);
  1143.         }
  1144.         else
  1145.         strcpy(LibrariesPath, Line);
  1146.         break;
  1147.     }
  1148.  
  1149.     ChangeDir(CrntPath);
  1150. }
  1151.  
  1152. /*****************************************************************************
  1153. * Routine to handle the DRAW pull down sub menu.                 *
  1154. *****************************************************************************/
  1155. static void HandleDrawMenu(int Index)
  1156. {
  1157.     DrawGenericStruct
  1158.         *NewDrawStruct = NULL;
  1159.     int i;
  1160.    
  1161.     if (ActiveWindowID < 0) {
  1162.     IntrQueryContinue("No active window to work on.",
  1163.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1164.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1165.                           INTR_WNDW_PLACE_CENTER);
  1166.         return;
  1167.     }
  1168.  
  1169.     if (Index >= 0) {
  1170.     if (IntrPopUpMenu(DrawPUMenu, INTR_WNDW_PULL_DOWN))
  1171.         Index = DrawPUMenu -> SelectedIndex;
  1172.     else
  1173.             Index = -1;
  1174.     }
  1175.     else
  1176.     Index += DIRECT_CALL_INDEX_OFFSET;
  1177.  
  1178.     GRSetViewPort(EEActiveBBox -> Xmin, EEActiveBBox -> Ymin,
  1179.               EEActiveBBox -> Xmax, EEActiveBBox -> Ymax);
  1180.     IntrPushCursorType();           /* Make sure cursor is IN active window. */
  1181.     PutCursorInActiveWindow();
  1182.  
  1183.     switch(Index) {
  1184.         case 0:        /* Draw Polly Line */
  1185.         NewDrawStruct = CreateNewPolylineStruct(ReturnCurrentWidth(),
  1186.             FALSE);
  1187.         break;
  1188.         case 1:        /* Draw Wire Connection */
  1189.         NewDrawStruct = CreateNewPolylineStruct(ReturnCurrentWidth(),
  1190.             TRUE);
  1191.         break;
  1192.     case 2:        /* Draw Bus Width Line Current Layer */
  1193.         NewDrawStruct = CreateNewPolylineStruct(GR_THICK_WIDTH,FALSE);
  1194.         break;
  1195.     case 3:
  1196.         NewDrawStruct = CreateNewConnectionStruct();
  1197.         break;
  1198.     case 4:
  1199.         NewDrawStruct = CreateNewTextStruct();
  1200.         break;
  1201.         case 5:
  1202.         NewDrawStruct = LibCreateNewPart();
  1203.         break;
  1204.     case 6:        /* Change Drawing Layer */
  1205.             SetLayer(); 
  1206.         /* IntrWndwPop(EEActiveWindow->IntrLibWindowID ,TRUE,FALSE); */
  1207.         ShowStatus(EEActiveWindow,0);
  1208.         break;
  1209.     case 7 :
  1210.         SetCommonColor();
  1211.         /* IntrWndwPop(EEActiveWindow->IntrLibWindowID ,TRUE,FALSE); */
  1212.         ShowStatus(EEActiveWindow,0);
  1213.         break;
  1214.     case 8 :
  1215.         i=SetColor();
  1216.         if(i!=-1){
  1217.         LayerPointer->CommonColor=i;
  1218.             ShowStatus(EEActiveWindow,0);
  1219.         }
  1220.         break;
  1221.     }
  1222.  
  1223.     if (NewDrawStruct != NULL) {
  1224.         NewDrawStruct -> Pnext = EEActiveWindow -> EEDrawList;
  1225.         EEActiveWindow -> EEDrawList = NewDrawStruct;
  1226.         if (!EEActiveWindow -> Modified) {
  1227.         EEActiveWindow -> Modified = TRUE;
  1228.         
  1229.         } 
  1230.     }
  1231.     
  1232.     IntrPopCursorType();
  1233. }
  1234.  
  1235. /*****************************************************************************
  1236. * Routine to handle the MODIFY pull down sub menu.                 *
  1237. *****************************************************************************/
  1238. static void HandleModifyMenu(int Index)
  1239. {
  1240.     BooleanType
  1241.     Modified = FALSE;
  1242.     DrawGenericStruct *DrawStruct;
  1243.  
  1244.     if (ActiveWindowID < 0) {
  1245.     IntrQueryContinue("No active window to work on.",
  1246.                   EEPopUpFrameColor, EEPopUpBackColor, EEPopUpForeColor,
  1247.                           EEPopUpXorColor, EEWindowsFrameWidth, &Cursor,
  1248.                           INTR_WNDW_PLACE_CENTER);
  1249.         return;
  1250.     }
  1251.  
  1252.     if (Index >= 0) {
  1253.     if (IntrPopUpMenu(ModifyPUMenu, INTR_WNDW_PULL_DOWN))
  1254.         Index = ModifyPUMenu -> SelectedIndex;
  1255.         else
  1256.             Index = -1;
  1257.     }
  1258.     else
  1259.     Index += DIRECT_CALL_INDEX_OFFSET;
  1260.  
  1261.     GRSetViewPort(EEActiveBBox -> Xmin, EEActiveBBox -> Ymin,
  1262.               EEActiveBBox -> Xmax, EEActiveBBox -> Ymax);
  1263.     IntrPushCursorType();           /* Make sure cursor is IN active window. */
  1264.     PutCursorInActiveWindow();
  1265.  
  1266.     switch(Index) {
  1267.         case 0: /* Move */
  1268.             Modified = (DrawStruct = PickStruct("Pick struct to move:", FALSE))
  1269.                                         != NULL &&
  1270.                 MoveStruct(DrawStruct);
  1271.             break;
  1272.         case 1: /* Copy */
  1273.         Modified = (DrawStruct = PickStruct("Pick struct to copy", FALSE))
  1274.                                         != NULL &&
  1275.             CopyStruct(DrawStruct);
  1276.             break;
  1277.         case 2: /* EditLibItem */
  1278.         Modified = EditLibraryItem();
  1279.         break;
  1280.     case 3: /* Delete */
  1281.         if ((DrawStruct = PickStruct("Pick struct to delete", FALSE))
  1282.                                         != NULL) {
  1283.         DeleteStruct(DrawStruct);
  1284.                 Modified = TRUE;
  1285.             }
  1286.             break;
  1287.         case 4: /* Undelete */
  1288.         Modified = UnDeleteStruct();
  1289.         break;
  1290.     case 5: /* Cut */
  1291.         if ((DrawStruct = PickStruct("Pick struct to cut", FALSE))
  1292.                                         != NULL) {
  1293.         CutStruct(DrawStruct);
  1294.             }
  1295.             break;
  1296.         case 6: /* Paste */
  1297.         Modified = PasteStruct();
  1298.             break;
  1299.         case 7: /* Drop */
  1300.         DropStruct();
  1301.             break;
  1302.     }
  1303.  
  1304.     if (Modified && !EEActiveWindow -> Modified) {
  1305.     EEActiveWindow -> Modified = TRUE;
  1306.      
  1307.     }
  1308.     IntrPopCursorType();
  1309. }
  1310.  
  1311. /*****************************************************************************
  1312. * Routine to handle the STATUS pull down sub menu.                 *
  1313. *****************************************************************************/
  1314. static void HandleStatusMenu(int Index)
  1315. {
  1316.     int i, NumLines;
  1317.     char *FullFileName, Line[LINE_LEN];
  1318.     FILE *f;
  1319.  
  1320.     if (Index >= 0) {
  1321.     if (IntrPopUpMenu(StatusPUMenu, INTR_WNDW_PULL_DOWN))
  1322.         Index = StatusPUMenu -> SelectedIndex;
  1323.         else
  1324.             Index = -1;
  1325.     }
  1326.     else
  1327.     Index += DIRECT_CALL_INDEX_OFFSET;
  1328.  
  1329.     switch(Index) {
  1330.         case 0: /* Help */
  1331.         if (HelpWindowID >= 0) {
  1332.         IntrWndwDelete(HelpWindowID, TRUE);
  1333.         HelpWindowID = -1;
  1334.             }
  1335.             else {
  1336.         if (coreleft() < 30000L) {
  1337.                 IntrQueryContinue("Not enough memory to pop help",
  1338.                       EEPopUpFrameColor, EEPopUpBackColor,
  1339.                                   EEPopUpForeColor, EEPopUpXorColor,
  1340.                                   EEWindowsFrameWidth, &Cursor,
  1341.                                   INTR_WNDW_PLACE_CENTER);
  1342.                     break;
  1343.                 }
  1344.  
  1345.                 sprintf(Line, "%s.hlp", PROGRAM_NAME);
  1346.                 if ((FullFileName = searchpath(Line)) != NULL &&
  1347.             (f = fopen(FullFileName, "rt")) != NULL &&
  1348.                     fgets(Line, LINE_LEN - 2, f) != NULL &&
  1349.                     sscanf(Line, "%d", &NumLines) == 1) {
  1350.             IntrDrawMessage("Loading Help...", EEPopUpForeColor,
  1351.                                        EEPopUpBackColor);
  1352.  
  1353.                     /* Unlike drawing window no horizontal scroll bar. */
  1354.                     ResizeBBox.Ymax += IntrWndwScrollBarWidth();
  1355.                 HelpWindowID = IntrWndwCreate(
  1356.                         ShowWindowName ? "Help" : NULL, EEWindowsFrameWidth,
  1357.                         &ResizeBBox, EERootWndwFrameColor, EERootWndwBackColor,
  1358.                         NULL, NULL, HelpWndwRefreshFunc);
  1359.             ResizeBBox.Ymax -= IntrWndwScrollBarWidth();
  1360.  
  1361.             IntrTextInitWindow(HelpWindowID, FALSE, EERootWndwForeColor,
  1362.                    EERootWndwForeColor,
  1363.                     INTR_SCRLBAR_NONE, INTR_SCRLBAR_LEFT,
  1364.                                    NumLines, 80);
  1365.  
  1366.                 for (i = 0; i < NumLines; i++) {
  1367.                 fgets(Line, LINE_LEN - 2, f);
  1368.                 IntrPrintf(HelpWindowID, FALSE, Line);
  1369.                     }
  1370.  
  1371.                     fclose(f);
  1372.  
  1373.                     IntrEraseMessage();
  1374.  
  1375.             IntrWndwResize(HelpWindowID, FALSE);
  1376.                     IntrWndwPop(HelpWindowID, TRUE, FALSE);
  1377.                 }
  1378.                 else {
  1379.                 IntrQueryContinue("Can not open help file",
  1380.                       EEPopUpFrameColor, EEPopUpBackColor,
  1381.                                   EEPopUpForeColor, EEPopUpXorColor,
  1382.                                   EEWindowsFrameWidth, &Cursor,
  1383.                                   INTR_WNDW_PLACE_CENTER);
  1384.                 }
  1385.             }
  1386.         break;
  1387.         case 1: /* Free Mem. */
  1388.             PrintMemoryFree();
  1389.             break;
  1390.         case 2: /* Get zoom factor. */
  1391.             sprintf(Line, "Current Zoom factor is %2.5lf",
  1392.                     pow(2.0, (double) (IntrWndwGetZoomFactor(ActiveWindowID) -
  1393.                        DEFAULT_ZOOM_FACTOR)));
  1394.         IntrQueryContinue(Line, EEPopUpFrameColor, EEPopUpBackColor,
  1395.                               EEPopUpForeColor, EEPopUpXorColor,
  1396.                               EEWindowsFrameWidth, &Cursor,
  1397.                               INTR_WNDW_PLACE_CENTER);
  1398.             break;
  1399.         case 3: /* Draw Text */
  1400.             i = GRDrawText;
  1401.             GRDrawText = IntrQueryYesNo("Draw text?", EEPopUpFrameColor,
  1402.                         EEPopUpBackColor, EEPopUpForeColor,
  1403.                         EEPopUpXorColor, EEWindowsFrameWidth,
  1404.                                         &Cursor, INTR_WNDW_PLACE_CENTER);
  1405.             if (i != GRDrawText)
  1406.             RedrawAllWindows();
  1407.             break;
  1408.         case 4: /* Text Scale */
  1409.             sprintf(Line, "%d", EETextScale);
  1410.             IntrQueryLine("Text Scale size [1..7]:", Line,
  1411.               LINE_LEN_SHORT - 1, EEPopUpFrameColor,
  1412.                           EEPopUpBackColor, EEPopUpForeColor,
  1413.                           EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1414.             if (sscanf(Line, "%d", &i) != 1 || i < 1 || i > 7)
  1415.             IntrQueryContinue("Wrong format/range, ignored",
  1416.                       EEPopUpFrameColor, EEPopUpBackColor,
  1417.                                   EEPopUpForeColor, EEPopUpXorColor,
  1418.                                   EEWindowsFrameWidth, &Cursor,
  1419.                                   INTR_WNDW_PLACE_CENTER);
  1420.             else
  1421.             EETextScale = i;
  1422.         break;
  1423.         case 5: /* Set auto pan */
  1424.             EEAutoPan =
  1425.             IntrQueryYesNo("Enable automatic panning?",
  1426.                    EEPopUpFrameColor, EEPopUpBackColor,
  1427.                                    EEPopUpForeColor, EEPopUpXorColor,
  1428.                                    EEWindowsFrameWidth, &Cursor,
  1429.                                    INTR_WNDW_PLACE_CENTER);
  1430.             break;
  1431.         case 6: /* Vert. Horiz. Lines */
  1432.             EEHVLineDrawing =
  1433.             IntrQueryYesNo("Draw only vertical/horizontal lines?",
  1434.                    EEPopUpFrameColor, EEPopUpBackColor,
  1435.                                    EEPopUpForeColor, EEPopUpXorColor,
  1436.                                    EEWindowsFrameWidth, &Cursor,
  1437.                                    INTR_WNDW_PLACE_CENTER);
  1438.             break;
  1439.         case 7: /* Snap Factor */
  1440.             sprintf(Line, "%d", EESnapDistance);
  1441.             IntrQueryLine("New snap factor [0..1024]:", Line,
  1442.               LINE_LEN_SHORT - 1, EEPopUpFrameColor,
  1443.                           EEPopUpBackColor, EEPopUpForeColor,
  1444.                           EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1445.             if (sscanf(Line, "%d", &i) != 1 || i < 1 || i > 1024)
  1446.             IntrQueryContinue("Wrong format/range, ignored",
  1447.                               EEPopUpFrameColor, EEPopUpBackColor,
  1448.                                   EEPopUpForeColor, EEPopUpXorColor,
  1449.                                   EEWindowsFrameWidth, &Cursor,
  1450.                                   INTR_WNDW_PLACE_CENTER);
  1451.             else
  1452.             EESnapDistance = i;
  1453.             break;
  1454.         case 8: /* Draw Line Width */
  1455.             sprintf(Line, "%d", ReturnCurrentWidth());
  1456.             IntrQueryLine("Set New Line Width [0..50]:", Line,
  1457.               LINE_LEN_SHORT - 1, EEPopUpFrameColor,
  1458.                           EEPopUpBackColor, EEPopUpForeColor,
  1459.                           EEWindowsFrameWidth, INTR_WNDW_PLACE_CENTER);
  1460.             if (sscanf(Line, "%d", &i) != 1 || i < 1 || i > 50)
  1461.             IntrQueryContinue("Wrong range, ignored",
  1462.                               EEPopUpFrameColor, EEPopUpBackColor,
  1463.                                   EEPopUpForeColor, EEPopUpXorColor,
  1464.                                   EEWindowsFrameWidth, &Cursor,
  1465.                                   INTR_WNDW_PLACE_CENTER);
  1466.             else
  1467.             SetCurrentWidth(i);
  1468.             break;
  1469.     }
  1470. }
  1471.  
  1472. /*****************************************************************************
  1473. * Given a full path file name returns a pointer to the file name only.         *
  1474. *****************************************************************************/
  1475. static char *GetFileName(char *FullPathName)
  1476. {
  1477.     int i = strlen(FullPathName) - 1;
  1478.  
  1479.     while (i >= 0 && FullPathName[i] != '\\' &&
  1480.                  FullPathName[i] != '/' &&
  1481.              FullPathName[i] != ':') i--;
  1482.     return i > 0 ? &FullPathName[i + 1] : FullPathName;
  1483. }
  1484.  
  1485. /*****************************************************************************
  1486. * Routine to refresh root window drawing.                     *
  1487. *****************************************************************************/
  1488. static void RootWndwRefreshFunc(int WindowID)
  1489. {
  1490.     IntrBBoxStruct *BBox = IntrWndwGetBBox(WindowID);
  1491.     int x = (BBox -> Xmax - BBox -> Xmin) / 2,
  1492.         y = (BBox -> Ymax - BBox -> Ymin) / 3;
  1493.  
  1494.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER);
  1495.  
  1496.     GRSetSTextStyle(GRFontName, GR_HORIZ_DIR, 8);
  1497.  
  1498.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_HIGH);
  1499.     GRSText(x + 8, y + 8, "EEdraw");
  1500.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_VHIGH);
  1501.     GRSText(x, y, "EEdraw");
  1502.  
  1503.     GRSetSTextStyle(GRFontName, GR_HORIZ_DIR, 2);
  1504.  
  1505.     y = y + 50;
  1506.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_HIGH);
  1507.     GRSText(x + 2, y + 2, "(c) Copyright 1989-91 Gershon Elber");
  1508.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_VHIGH);
  1509.     GRSText(x, y, "(c) Copyright 1989-91 Gershon Elber");
  1510.  
  1511.     y = y * 2;
  1512.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_HIGH);
  1513.     GRSText(x + 2, y + 2, "& Peter Cooper 1992- for Ver 2.4");
  1514.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_VHIGH);
  1515.     GRSText(x, y, "& Peter Cooper 1992- for Ver 2.4");
  1516.  
  1517.     IntrWndwSetRefreshFunc(WindowID, NULL);    /* Disable further refreshes. */
  1518. }
  1519.  
  1520. /*****************************************************************************
  1521. * Routine to refresh Layer window drawing.                     *
  1522. *****************************************************************************/
  1523. static void LayerWndwRefreshFunc(int WindowID)
  1524. {
  1525. /*    IntrBBoxStruct *BBox = IntrWndwGetBBox(WindowID);
  1526.     int x = (BBox -> Xmax - BBox -> Xmin) / 2,
  1527.         y = (BBox -> Ymax - BBox -> Ymin) / 3;
  1528.  
  1529.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER);
  1530.  
  1531.     GRSetSTextStyle(GRFontName, GR_HORIZ_DIR, 8);
  1532.  
  1533.     IntrAllocColor(EERootWndwForeColor, INTR_INTENSITY_HIGH);
  1534.   */ 
  1535.     
  1536. }
  1537. /*****************************************************************************
  1538. * Routine to refresh help window drawing.                     *
  1539. *****************************************************************************/
  1540. static void HelpWndwRefreshFunc(int WindowID)
  1541. {
  1542.     IntrTextWndwRefresh(WindowID);
  1543. }
  1544.  
  1545. /*****************************************************************************
  1546. * Routine to refresh root window drawing.                     *
  1547. *****************************************************************************/
  1548. static void DataWndwRefreshFunc(int WindowID)
  1549. {
  1550.     int i, x, y;
  1551.     IntrBType IsVertical;
  1552.     IntrRType Zoom, Value, XFrac, YFrac;
  1553.     EEWindowStruct *TmpWndw,
  1554.         *Window = NULL;
  1555.     IntrBBoxStruct *BBox;
  1556.  
  1557.     /* First do the most likely thing... */
  1558.     if (WindowID == EEActiveWindow -> IntrLibWindowID)
  1559.     Window = EEActiveWindow;
  1560.     else {
  1561.     for (Window = EEWindowsList; Window != NULL; Window = Window -> Pnext)
  1562.         if (WindowID == Window -> IntrLibWindowID)
  1563.                 break;
  1564.     }
  1565.  
  1566.     if (Window == NULL) IntrFatalError("Wrong Window ID.");
  1567.  
  1568.     /* Update the scroll bars. */
  1569.     i = IntrWndwGetZoomFactor(Window -> IntrLibWindowID) - DEFAULT_ZOOM_FACTOR;
  1570.     if (i > 0)
  1571.     Zoom = 1 << i;
  1572.     else if (i < 0)
  1573.     Zoom = 1.0 / (1 << (-i));
  1574.     else
  1575.     Zoom = 1.0;
  1576.     BBox = IntrWndwGetBBox(Window -> IntrLibWindowID);
  1577.     XFrac = (BBox -> Xmax - BBox -> Xmin) /
  1578.             (Window -> PageXSize * Zoom + (BOUNDARY_WIDTH << 1));
  1579.     YFrac = (BBox -> Ymax - BBox -> Ymin) /
  1580.                (Window -> PageYSize * Zoom + (BOUNDARY_WIDTH << 1));
  1581.  
  1582.     if (IntrWndwIsScrollBarEvent(Window -> IntrLibWindowID, &IsVertical,
  1583.                                         &Value)) {
  1584.     /* This refresh is a result of a scroll bar event on the window. */
  1585.     IntrWndwGetPanFactors(Window -> IntrLibWindowID, &x, &y);
  1586.         if (IsVertical) {
  1587.         if (YFrac > 1.0)
  1588.         y = DEFAULT_INV_ZOOM(Window -> PageYSize) / 2;
  1589.             else {
  1590.         Value = Value + YFrac / 2.0;
  1591.         if (Value > 1.0 - YFrac / 2.0) Value = 1.0 - YFrac / 2.0;
  1592.         y = Value * DEFAULT_INV_ZOOM(Window -> PageYSize);
  1593.             }
  1594.         }
  1595.         else {
  1596.         if (XFrac > 1.0)
  1597.         x = DEFAULT_INV_ZOOM(Window -> PageXSize) / 2;
  1598.             else {
  1599.         Value = Value + XFrac / 2.0;
  1600.         if (Value > 1.0 - XFrac / 2.0) Value = 1.0 - XFrac / 2.0;
  1601.         x = Value * DEFAULT_INV_ZOOM(Window -> PageXSize);
  1602.         }
  1603.         }
  1604.     IntrWndwSetPanning(Window -> IntrLibWindowID, x, y);
  1605.         GRSetPanFactors(x, y);
  1606.     }
  1607.  
  1608.     IntrWndwGetPanFactors(Window -> IntrLibWindowID, &x, &y);
  1609.     if (XFrac >= 1.0)
  1610.     IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, FALSE, 0.0, 1.0);
  1611.     else
  1612.         IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, FALSE,
  1613.         x / ((IntrRType) DEFAULT_INV_ZOOM(Window -> PageXSize)) -
  1614.                 XFrac / 2.0,
  1615.         XFrac);
  1616.     if (YFrac >= 1.0)
  1617.     IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, TRUE, 0.0, 1.0);
  1618.     else
  1619.     IntrWndwUpdateScrollBar(Window -> IntrLibWindowID, TRUE,
  1620.         y / ((IntrRType) DEFAULT_INV_ZOOM(Window -> PageYSize)) -
  1621.                 YFrac / 2.0,
  1622.         YFrac);
  1623.  
  1624.     /* Redraw the window content. */
  1625.     TmpWndw = EEActiveWindow;    /* Save current active window pointer */
  1626.     EEActiveWindow = Window;    /* set up pointer for Layer Drawing */
  1627.  
  1628.     RedrawStructList(Window -> EEDrawList, GR_COPY_PUT, EE_DRAW_COLOR);
  1629.     EEActiveWindow = TmpWndw;    /* restore Main Active Window Pointer */
  1630.  
  1631.     /* Draw the window page border. */
  1632.     GRSetWriteMode(GR_COPY_PUT);
  1633.     IntrAllocColor(EEHighLightColor, INTR_INTENSITY_VHIGH);
  1634.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_THICK_WIDTH);
  1635.     GRMoveTo(0, 0);
  1636.     GRLineTo(0, DEFAULT_INV_ZOOM(Window -> PageYSize));
  1637.     GRLineTo(DEFAULT_INV_ZOOM(Window -> PageXSize),
  1638.                            DEFAULT_INV_ZOOM(Window -> PageYSize));
  1639.     GRLineTo(DEFAULT_INV_ZOOM(Window -> PageXSize), 0);
  1640.     GRLineTo(0, 0);
  1641.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  1642. }
  1643.  
  1644. /*****************************************************************************
  1645. * Routine to handle key bindings.                         *
  1646. *****************************************************************************/
  1647. static void HandleSameAgain(int KeyStroke)
  1648. {
  1649.     HandleKeyBindings(LastKeyStroke);
  1650. }
  1651.  
  1652. /*****************************************************************************
  1653. * Routine to handle key bindings.                         *
  1654. *****************************************************************************/
  1655. static void HandleKeyBindings(int KeyStroke)
  1656. {
  1657.     int i;
  1658.  
  1659.     LastKeyStroke = KeyStroke;
  1660.  
  1661.     for (i = 0; i < KeyBindingCount; i++)
  1662.     if (KeyBindingList[i].ScanCode == KeyStroke) {
  1663.         /* Activate the related function. */
  1664.         PDActionFuncs[KeyBindingList[i].Menu](KeyBindingList[i].MenuEntry -
  1665.                              DIRECT_CALL_INDEX_OFFSET);
  1666.         break;
  1667.         }
  1668. }
  1669.  
  1670. /*****************************************************************************
  1671. * Routine to read the key binding file if such exists.                 *
  1672. *****************************************************************************/
  1673. static BooleanType ReadKeyBindings(char *Name)
  1674. {
  1675.     int i, j, Len, ScanCode,
  1676.     LineNum = 0;
  1677.     IntrBType FuncFound;
  1678.     FILE *f;
  1679.     char Buffer[LINE_LEN_SHORT], *FunctionName,    *KeyName, *ScanCodeStr, *p;
  1680.  
  1681.     strcpy(Buffer, Name);            /* Remove old type if has one... */
  1682.     if ((p = strrchr(Buffer, '.')) != NULL) *p = 0;
  1683.     strcat(Buffer, ".BND");           /* ... and add the binding file type. */
  1684.  
  1685.     /* Search in path, and if fails, return silently: */
  1686.     p = searchpath(Buffer);
  1687.     if (p == NULL || (f = fopen(p, "rt")) == NULL) return TRUE;
  1688.  
  1689.     while (fgets(Buffer, LINE_LEN_SHORT - 1, f)) {
  1690.     LineNum++;
  1691.     if (Buffer[0] == ';' || Buffer[0] == '\n' || Buffer[0] == '\r')
  1692.         continue;
  1693.  
  1694.     if ((FunctionName = strtok(Buffer, " \t\n\r")) == NULL ||
  1695.         (KeyName = strtok(NULL, " \t\n\r")) == NULL ||
  1696.         (ScanCodeStr = strtok(NULL, " \t\n\r")) == NULL ||
  1697.         sscanf(ScanCodeStr, "%d", &ScanCode) != 1) {
  1698.         fprintf(stderr, "Wrong format, binding file \"%s\", line %d.\n",
  1699.                                 p, LineNum);
  1700.         fclose(f);
  1701.         return FALSE;
  1702.     }
  1703.  
  1704.     Len = strlen(FunctionName);
  1705.     FuncFound = FALSE;
  1706.         if (strncmp("SameAgain", FunctionName, Len) == 0) {
  1707.         IntrRegisterKeyStroke(ScanCode, HandleSameAgain);
  1708.             FuncFound = TRUE;
  1709.         }
  1710.     else
  1711.         for (i = 0; !FuncFound && i < ALL_POP_UP_SIZE; i++)
  1712.             for (j = 0; !FuncFound && j < AllPUSizes[i]; j++)
  1713.             if (strncmp(AllPUStrs[i][j], FunctionName, Len) == 0 &&
  1714.                 KeyBindingCount < MAX_KEY_BINDINGS) {
  1715.                 KeyBindingList[KeyBindingCount].ScanCode = ScanCode;
  1716.                         KeyBindingList[KeyBindingCount].Menu = i;
  1717.                         KeyBindingList[KeyBindingCount++].MenuEntry = j;
  1718.                 IntrRegisterKeyStroke(ScanCode, HandleKeyBindings);
  1719.                 if (strlen(KeyName) > 4) KeyName[4] = 0;
  1720.                     Len = strlen(AllPUStrs[i][j]) - strlen(KeyName) - 2;
  1721.                 sprintf(&AllPUStrs[i][j][Len], "[%s]", KeyName);
  1722.                         FuncFound = TRUE;
  1723.             }
  1724.     if (!FuncFound) {
  1725.         fprintf(stderr,
  1726.         "No such function as \"%s\", binding file \"%s\", line %d.\n",
  1727.                         FunctionName, p, LineNum);
  1728.         fclose(f);
  1729.         return FALSE;
  1730.     }
  1731.     }
  1732.  
  1733.     fclose(f);
  1734.  
  1735.     return TRUE;
  1736. }
  1737.  
  1738. /*****************************************************************************
  1739. * My Routine to    allocate dynamic memory. All program requests must call this *
  1740. * routine (no direct call to malloc). Dies if no memory.             *
  1741. *****************************************************************************/
  1742. VoidPtr MyMalloc(unsigned size)
  1743. {
  1744.     static int Unlocked = TRUE;
  1745.     static time_t LastTime = 0;
  1746.     char *p;
  1747.     time_t CrntTime;
  1748.  
  1749.  
  1750. #ifdef DEBUG_MALLOC_TC20
  1751.     unsigned int *i;
  1752.  
  1753.     size += 6;
  1754. #endif /* DEBUG_MALLOC_TC20 */
  1755.  
  1756.     p = malloc(size);
  1757.     if (p == NULL)
  1758.     FatalError("Not enough memory, exit\n");
  1759.     if (Unlocked && coreleft() < 32768L) {
  1760.     /* Unlocked is used to make sure we would not recurse from the below */
  1761.     /* Routines when it calls MyMalloc - this may cause infinite loop... */
  1762.     Unlocked = FALSE;
  1763.  
  1764.     time(&CrntTime);
  1765.     if (CrntTime - LastTime > 30) {    /* Let user know every 30 second. */
  1766.         IntrQueryContinue("Free memory too small - dangerous to continue",
  1767.                               EEPopUpFrameColor, EEPopUpBackColor,
  1768.                               EEPopUpForeColor, EEPopUpXorColor,
  1769.                               EEWindowsFrameWidth, &Cursor,
  1770.                               INTR_WNDW_PLACE_CENTER);
  1771.         LastTime = CrntTime;
  1772.     }
  1773.     Unlocked = TRUE;
  1774.     }
  1775.  
  1776. #ifdef DEBUG_MALLOC_TC20
  1777.     /* Do the following tests on the memory allocated:                 */
  1778.     /* 1. Uses TC 2.0 heuristic to make sure pointer are legal by comparing  */
  1779.     /*    their offset to the constant 8.                     */
  1780.     /* 2. Mark the end of allocated memory for over written test in MyFree.  */
  1781.     if (FP_OFF(p) != 8) {
  1782.     GetContinueQuestion(
  1783.         "Bogus pointer detected - unsafe to continue. Report it as 1.",
  1784.         CENTER_CENTER);
  1785.     }
  1786.     strcpy(&p[size-4], "ILG");             /* Put a marker at the end. */
  1787.     i = (unsigned int *) p;    /* Save size of this block at the begging and */
  1788.     *i = size;                  /* return a pointer just after it. */
  1789.     p += 2;
  1790. #endif /* DEBUG_MALLOC_TC20 */
  1791.  
  1792.     return p;
  1793. }
  1794.  
  1795. /*****************************************************************************
  1796. * My Routine to    free dynamic memory. All program requests must call this     *
  1797. * routine (no direct call free).                         *
  1798. *****************************************************************************/
  1799. void MyFree(VoidPtr p)
  1800. {
  1801. #ifdef DEBUG_MALLOC_TC20
  1802.     char *pc = (char *) p;
  1803.     unsigned int *i, size;
  1804.  
  1805.     /* Do the following tests on the memory allocated.                 */
  1806.     /* 1. Uses TC 2.0 heuristic to make sure pointer are legal by comparing  */
  1807.     /*    their offset to constant 8 (+2 as we skip the size we entered).    */
  1808.     /* 2. Test the mark at the end of the allocated memory for over written. */
  1809.     if (FP_OFF(p) != 8 + 2) {
  1810.     GetContinueQuestion(
  1811.         "Bogus pointer detected - unsafe to continue. Report it as 2.",
  1812.         CENTER_CENTER);
  1813.     return;
  1814.     }
  1815.     pc -= 2;
  1816.     i = (unsigned int *) pc;
  1817.     size = *i;
  1818.     if (strcmp(&pc[size-4], "ILG") != 0) {
  1819.     GetContinueQuestion(
  1820.         "Overwritten pointer detected - unsafe to continue. Report it as 3.",
  1821.         CENTER_CENTER);
  1822.     return;
  1823.     }
  1824.     p = pc;
  1825. #endif /* DEBUG_MALLOC_TC20 */
  1826.  
  1827. #ifdef DEBUG_MALLOC_TCPP
  1828.     int i = heapchecknode(p);
  1829.  
  1830.     switch(heapchecknode(p)) {
  1831.     case _HEAPEMPTY:
  1832.     case _HEAPCORRUPT:
  1833.     case _BADNODE:
  1834.     case _FREEENTRY:
  1835.     GetContinueQuestion(
  1836.         "Bogus pointer detected - unsafe to continue. Report it as 4.",
  1837.         CENTER_CENTER);
  1838.         return;
  1839.     }
  1840. #endif /* DEBUG_MALLOC_TCPP */
  1841.  
  1842.     free(p);
  1843. }
  1844.  
  1845. #ifdef DEBUG_MALLOC_TC20
  1846.  
  1847. /*****************************************************************************
  1848. * Define local strdup as we offset the pointers by 2 to save the size and    *
  1849. * calling to MyFree with pointers allocated via strdup will result with a    *
  1850. * fatal error...                                 *
  1851. *****************************************************************************/
  1852. char *strdup(const char *Str)
  1853. {
  1854.     char *NewStr = (char *) MyMalloc(strlen(Str) + 1);
  1855.  
  1856.     strcpy(NewStr, Str);
  1857.  
  1858.     return NewStr;
  1859. }
  1860.  
  1861. #endif /* DEBUG_MALLOC_TC20 */
  1862.  
  1863. /*****************************************************************************
  1864. * MyExit routine. Note it might call to CloseGraph without calling         *
  1865. * InitGraph(), or call MouseClose() without MouseInit() etc. and it is the   *
  1866. * responsibility of the individual modules to do nothing in these cases.     *
  1867. *****************************************************************************/
  1868. void MyExit(int ExitCode)
  1869. {
  1870.     IntrClose();               /* Close the interaction library. */
  1871.  
  1872.     RestoreCtrlBrk();
  1873.  
  1874.     ChangeDir(InitialPath);
  1875.  
  1876.     exit(ExitCode);
  1877. }
  1878.  
  1879. /*****************************************************************************
  1880. * Same as MyExit routine, but print error message to stderr.             *
  1881. *****************************************************************************/
  1882. void FatalError(char *ErrMsg)
  1883. {
  1884.     IntrClose();               /* Close the interaction library. */
  1885.  
  1886.     fprintf(stderr, "EEDRAW: %s\n", ErrMsg);
  1887.  
  1888.     RestoreCtrlBrk();
  1889.  
  1890.     ChangeDir(InitialPath);
  1891.  
  1892.     exit('F');
  1893. }
  1894.